/* -------------------------------------------------------------------------- *
   TestWinUnit - Maria Blees (maria.blees@microsoft.com)

   File: NulFile.cpp
   This class instantiates the "NUL" file (device) for reading or writing.
 * -------------------------------------------------------------------------- */
#include "NulFile.h"

#include <tchar.h>

NulFile::NulFile()
{
    SECURITY_ATTRIBUTES securityAttributes = {
        sizeof(SECURITY_ATTRIBUTES),
        NULL,   // default security descriptor
        TRUE    // handle is inheritable
    };

    _handle = ::CreateFile(_T("NUL"), 
        GENERIC_READ | GENERIC_WRITE, 
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        &securityAttributes,
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL,
        NULL
        );
}

NulFile::~NulFile()
{
    ::CloseHandle(_handle);
}

NulFile::operator HANDLE()
{
    return _handle;
}
